package com.atguigu.chapter12

object MatchExercise02 {
  def main(args: Array[String]): Unit = {

    for (ch <- "+-3!") {
      var sign = 0
      var digit = 0
      ch match {
        // 注意如果后面有下划线那么_就不是默认了,去掉if的话都会进入默认分支
        case _ if ch > 10000 => digit = 3
        case '+' => sign = 1
        case '-' => sign = -1
        // 注意默认匹配尽量都写上,当有元素不能匹配到任何case的时候会报错.
        case _ => println("没有任何匹配~~~")
      }
      println(ch + " " + sign + " " + digit)
    }
  }
}
